package com.xijia;

import java.io.*;


/**
 * 序列化破解枚举（先天性安全，无法破解）
 * @author wangsong
 * @date 2020/9/5 0005 10:30
 * @return
 * @version 1.0.0
 */
public class Test003 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // 1.将对象序列化存入到本地文件中
        FileOutputStream fos = new FileOutputStream("d:/code/a.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        Singleton07 instance1 = Singleton07.INSTANCE;
        oos.writeObject(Singleton07.INSTANCE);
        oos.close();
        fos.close();

        //2.从硬盘中反序列化对象到内存中
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("d:/code/a.txt"));
        Singleton07 instance2 = (Singleton07) ois.readObject();
        /**
         * 输出true， 枚举类没有被重新创建，原数据绝对安全
         */
        System.out.println(instance1 == instance2);
    }
}
